<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>

<body>
    <textarea name="" id="" cols="30" rows="10"></textarea>
    <button>发布</button>
    <ul></ul>
    <script>
        var btn = document.querySelector('button')
        var ul = btn.nextElementSibling
        var ta = btn.previousElementSibling
        btn.onclick = function() {
            if (ta.value == '') {
                alert('请输入内容')
                return false;
            }
            var li = document.createElement('li')
            li.innerHTML = ta.value + "<a href='javascript:;'>删除</a>"
            ta.value = ''
            ul.insertBefore(li, ul.children[0])
            var a = document.querySelectorAll('a')
            for (var i = 0; i < a.length; i++) {
                a[i].onclick = function() {
                    ul.removeChild(this.parentNode);
                }
            }
        }
    </script>
</body>

</html>